package cn.yjh.config;

import cn.yjh.utils.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @DESC:
 * @AUTHOR: YouJinhua
 * @DATE: 2021-11-25 22:27:08
 * @VERSION: 1.0
 */
public class ConfigurationManager {

    public static final String ACTIVE_CONFIGURATION = "activeConfiguration";
    public static final String BOOTSTRAP_CONFIGURATION = "bootstrapConfiguration";

    private Map<String,Properties> configResources = new LinkedHashMap<>();

    public void addConfigResource(String configName, Properties properties){
        this.configResources.put(configName,properties);
    }

    public String getConfiguration(String key){
        String value = null;
        Set<String> configNames = this.configResources.keySet();
        for(String configName : configNames){
            Properties prop = this.configResources.get(configName);
            value = String.valueOf(prop.get(key));
            if(StringUtils.isNotEmpty(value)){
                break;
            }
        }
        return value;
    }

    public boolean hasActiceConfiguration(){
        return this.configResources.containsKey(ACTIVE_CONFIGURATION);
    }
}
